﻿using BussinessObject.ObjectTwo;
using Class_Entity.ObjectTwo;
using DataAccess.ObjectTwo;
using ProjectHK3.App_Code;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectHK3.ObjectTwo
{
    public partial class OrderList1 : System.Web.UI.Page
    {
        B_LoadDrop ex = new B_LoadDrop();
        DataTable tb = new DataTable();
        B_LoadGidAD fx = new B_LoadGidAD();
        D_Delete kx = new D_Delete();
        B_Search gx = new B_Search();
        Orders jx = new Orders();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {                
                loadData();
            }

        }
        public void loadData()
        {
            DropDownList3.DataSource = ex.service();
            DropDownList3.DataTextField = "SERVICE_NAME";
            DropDownList3.DataValueField = "SERVICE_ID";
            DropDownList3.DataBind();

            DropDownList1.DataSource = ex.Bran();
            DropDownList1.DataTextField = "BRANCH_NAME";
            DropDownList1.DataValueField = "BRANCH_ID";
            DropDownList1.SelectedValue = Session["UserBran"].ToString();
            DropDownList1.DataBind();
           

            DropDownList2.DataSource = ex.Bran();
            DropDownList2.DataTextField = "BRANCH_NAME";
            DropDownList2.DataValueField = "BRANCH_ID";
            DropDownList2.DataBind();

            tb = fx.loadOder();
            _grwOrderList.DataSource = tb;
            _grwOrderList.DataBind();
        }
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                int tam;
                if (CheckBox1.Checked == true)
                {
                    tam = 1;
                }
                else
                {
                    tam = 0;
                }
                tb = gx.loadsearchOder(int.Parse(DropDownList1.SelectedValue.ToString()), int.Parse(DropDownList2.SelectedValue.ToString()), TextBox1.Text, int.Parse(DropDownList3.SelectedValue.ToString()), DropDownList4.Text.ToString(), TextBox3.Text, tam);
                _grwOrderListSearch.DataSource = tb;
                _grwOrderListSearch.DataBind();
            }
            catch (Exception ex)
            {
                Alert.Show(ex.Message);
            }
        }

        protected void _lbtDelete_Command(object sender, CommandEventArgs e)
        {
            Session["Order"] = Convert.ToInt32(e.CommandArgument.ToString());
            if (kx.DeleteOrder(int.Parse(Session["Order"].ToString())) == true)
            {
                Alert.Show("Delete Suscessful!");
                loadData();
            }
            else
            {
                Alert.Show("You can't delete. Beacuse it is being used.");
                loadData();
            }
        }

        protected void _lbtDetails_Command(object sender, CommandEventArgs e)
        {
            Session["Order"] = Convert.ToInt32(e.CommandArgument.ToString());
            try
            {
                jx = gx.ORDERSDETAIL(int.Parse(Session["Order"].ToString()));
            }
            catch (Exception)
            {
                Response.Redirect("../ObjectTwo/OrderInternalDetail.aspx");
            }
                if (jx.IS_INTERNAL_DELIVERY.ToString() == "0")
                {
                    Response.Redirect("../ObjectTwo/OrderListDetail.aspx");
                }else            
               {
                  Response.Redirect("../ObjectTwo/OrderInternalDetail.aspx");
               }
            
        }
    }
}